package metier;

import java.awt.Color;

import utiles.K;

public class Pheromone extends Element {

	private int concentration;
	private int evaporation;
	private final Position direction;

	public Pheromone(int concentration, int evaporation, Position direction) {
		super(1, 1);
		this.setConcentration(concentration);
		this.setEvaporation(evaporation);
		this.couleur = Color.ORANGE;
		this.direction = direction;
	}
	
	@Override
	public void agir(Carte c) {
		this.concentration -= this.evaporation;
		if (this.concentration > 0) {
			this.couleur = this.darken(Color.ORANGE, new Double (this.concentration) / K.CONCENTRATION_MAX);
			this.setChanged();
			this.notifyObservers();
		} else {
			c.removeElement(this);
		}
	}

	private Color darken(Color color, double fraction) {
	    /*int red   = (int) Math.round(Math.max(0, color.getRed()   * (1 - fraction)));
	    int green = (int) Math.round(Math.max(0, color.getGreen() * (1 - fraction)));
	    int blue  = (int) Math.round(Math.max(0, color.getBlue()  * (1 - fraction)));*/

//	    int alpha = (int) ( 255 *  (fraction) );
	    
	    return new Color(color.getRed(), color.getGreen(), color.getBlue());
//	    return new Color(255, 165, 0, alpha);

	}

	public int getConcentration() {
		return concentration;
	}

	public void setConcentration(int concentration) {
		this.concentration = concentration * K.COEFF_CONCENTRATION;
	}

	public int getEvaporation() {
		return evaporation;
	}

	public void setEvaporation(int evaporation) {
		this.evaporation = evaporation * K.COEFF_EVAPORATION;
	}
	
	public Position getDirection() {
		return direction;
	}
}
